package com.itboye.mengwu.app.ui.mymeng;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.alipay.android.phone.mrpc.core.ad;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseFragment;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.inageview.ItemEntity;
import com.itboye.inageview.ListItemAdapter;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.adapter.ShoPingAdapter;
import com.itboye.mengwu.app.adapter.ShopShngPingAdapter;
import com.itboye.mengwu.data.model.LuntanTieZiBean;
import com.itboye.mengwu.data.model.MyPingJiaBean;
import com.itboye.mengwu.data.model.MyTieZiCenterBean;
import com.itboye.mengwu.data.model.MyZengSongPingJiaBean;
import com.itboye.mengwu.data.model.ShopPingJiabean;
import com.itboye.mengwu.data.presenter.MyTieZiCenterPresenter;
import com.itboye.mengwu.widget.XListView;
import com.itboye.mengwu.widget.XListView.IXListViewListener;

public class ZengSongFrgment extends BaseFragment implements Observer, IXListViewListener {

	/** Item数据实体集合 */
	private MyZengSongPingJiaBean arrlist, arrlistTwo;
	/** ListView对象 */
	private XListView lsitviewme;
	// private RoundImage image;
	private ImageView back;
	MyTieZiCenterPresenter Presenter;
	ShopPingJiabean jiabean;
	private int page_no = 1;
	private int page_size = 10;
	boolean ShangLaflag = false;
	// LuntanTieZiBean model;
	String uid;
	int num;
	ShopShngPingAdapter adapter;

	//

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.fragment_shangping;
	}

	@Override
	public void onMyActivityCreated() {
		// TODO Auto-generated method stub

		lsitviewme.setXListViewListener(this);
		lsitviewme.setPullLoadEnable(true);
		lsitviewme.setPullRefreshEnable(true);
		arrlist = new MyZengSongPingJiaBean();

		Presenter = new MyTieZiCenterPresenter(this);
		uid = (String) SPUtils.get(getActivity(), null, SpPublicParams.UID, "");
		arrlist.setUid(uid);
		// Presenter.MyPingJia(uid);
		Presenter.MyZengSongPingJia(uid, "", page_no + "", page_size + "");
		showProgressDialog("数据加载中", true);

	}

	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub

		ResultEntity entity = handlerError(arg1);
		if (entity != null) {
			if (entity.getEventType() == Presenter.MyZengSongPingjiaSucess) {
				try {
					arrlist = (MyZengSongPingJiaBean) entity.getData();

					if (ShangLaflag == true) {
						arrlistTwo.getList().addAll(arrlist.getList());

						adapter.upDate(getActivity(), arrlistTwo);

						adapter.notifyDataSetChanged();
					} else {
						adapter = new ShopShngPingAdapter(getActivity(), arrlist);
						lsitviewme.setAdapter(adapter);
						arrlistTwo = arrlist;

					}

					// adapter=new ShopShngPingAdapter(getActivity(), arrlist);
					//// ByAlert.alert(""+entity.getData());
					//
					//// System.out.println("我的bean"+jiabean);
					// lsitviewme.setAdapter(adapter);
					System.out.println(">>>>>>>>><<<<<<<<<<<<<" + entity.getData());
				} catch (Exception e) {

					ByAlert.alert("" + entity.getData());

				}
			}
			stopLoad();
			try {
				closeProgressDialog();
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		ShangLaflag = false;
		page_no = 1;
		page_size = 10;
		// Presenter.MyPingJia(uid);
		Presenter.MyZengSongPingJia(uid, "", page_no + "", page_size + "");
		showProgressDialog("数据加载中", true);
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		ShangLaflag = true;
		page_no++;
		page_size++;
		// Presenter.MyPingJia(uid);
		Presenter.MyZengSongPingJia(uid, "", page_no + "", page_size + "");
		showProgressDialog("数据加载中", true);
	}

	public void stopLoad() {
		lsitviewme.stopLoadMore();
		lsitviewme.stopRefresh();
	}

}
